package pl.prv.polanie.client.widgets.table.subwidgets;

import pl.prv.polanie.client.widgets.table.CustomTable;

import com.google.gwt.user.client.ui.FocusListener;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Janusz Prokulewicz
 * Created: Jun 21, 2008
 */
public class TableTextBox extends TextBox {
	
	private static final String STYLE__TABLE_TEXT_BOX = "swo-TableTextBox";
	
	
//	private final Label sourceWidget;
	
	public TableTextBox(final Label sourceWidget, final CustomTable parentFT, final int row, final int column) {
		addStyleName(STYLE__TABLE_TEXT_BOX);
//		this.sourceWidget = sourceWidget;
		
		setText(sourceWidget.getText());
		
		final TextBox tb = this;
		addFocusListener(new FocusListener() {
			public void onFocus(Widget sender) {
			}
			public void onLostFocus(Widget sender) {
				parentFT.remove(TableTextBox.this);
				parentFT.setWidget(row, column, sourceWidget);
				sourceWidget.setText(getText());
				RootPanel.get().remove(tb);
			}
		});
		
		
	}
	
	public void setCursorPosAtEnd() {
		setCursorPos(getText().length());
	}
	
}
